package com.mentalhealthplatform.teacherV2.controller;

import com.mentalhealthplatform.appModels.Warning;
import com.mentalhealthplatform.teacherV2.service.WarningServiceV2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/warnings")
public class WarningControllerV2 {
    @Autowired
    private WarningServiceV2 warningServiceV2;

    // 获取所有测评信息
    @GetMapping
    public List<Warning> getAllWarnings() {
        return warningServiceV2.getAllWarnings();
    }

    // 根据 ID 获取测评信息
    @GetMapping("/{id}")
    public ResponseEntity<Warning> getWarningById(@PathVariable Long id) {
        Warning warning = warningServiceV2.getWarningById(id);
        if (warning == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(warning);
    }

    // 创建测评信息
    @PostMapping
    public Warning createWarning(@RequestBody Warning warning) {
        return warningServiceV2.saveWarning(warning);
    }

    // 根据 ID 删除测评信息
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteWarning(@PathVariable Long id) {
        warningServiceV2.deleteWarning(id);
        return ResponseEntity.noContent().build();
    }
}